package Easy;

public class LC0206 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode reverseList(ListNode head) {
        if (head == null) return null;
        ListNode left = head, middle = head.next;
        if (middle == null) return head;
        ListNode right = middle.next;
        head.next = null;

        while (right != null) {
            middle.next = left;
            left = middle;
            middle = right;
            right = right.next;
        }

        middle.next = left;
        return middle;
    }
}
